﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PlayerParse
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // 读取配置项
            string portValue = ConfigurationManager.AppSettings["Port"];

            if (portValue == null)
            {
                portValue = "12360";
                UpdateSetting("Port", portValue);
            }
            MyHttpServer httpserver = new MyHttpServer(int.Parse(portValue));
            Console.WriteLine($"端口：{portValue}");
            httpserver.listen();
            while (true)
            {
                var cmd=Console.ReadLine();
                if (cmd=="exit")
                {
                    break;
                }
            }
        }
        static void UpdateSetting(string key, string value)
        {
            Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            KeyValueConfigurationCollection settings = configuration.AppSettings.Settings;

            if (settings[key] == null)
            {
                settings.Add(key, value);
            }
            else
            {
                settings[key].Value = value;
            }

            configuration.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection(configuration.AppSettings.SectionInformation.Name);
        }
    }
}
